<?php

/**
 * Created by phpstorem.
 * User: yangakw@qq.com
 * Sign: 猥琐发育，别浪
 * Date: 2018-06-23
 * Time: 上午 9:59
 */
class Article extends CI_Model
{
    public function by_code($code)
    {
        $data = $this->db->where("code",$code)->from('article')->get()->row();
        return $data;
    }
    public function del_by_id($id)
    {
        $data = $this->db->where("id",$id)->from('article')->delete();
        return $data;
    }
    public function by_user_id($user_id)
    {
        $data = $this->db->where("user_id",$user_id)->from('article')->get()->result();
        return $data;
    }
    public function save($data){
        $code = isset($data["code"])?$data["code"]:'';
        if(empty($code)){
            return false;
        }
        $fetch_data = $this->by_code($code);
        if(empty($fetch_data)){
            $this->db->insert("article",$data);
        }else{
            $id = isset($data->id)?$data->id:0;
            $this->db->where('id', $id);
            $this->db->update('article', $data);
        }
        return true;
    }
}